home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr25
/
gnuplsrc.zip
/
DIALOGS.C
next >
Wrap
C/C++ Source or Header
|
1993-03-21
|
15KB
|
389 lines
#ifdef INCRCSDATA
static char RCSid[]="$Id: dialogs.c,v 1.2 1992/07/26 12:37:10 fearick Exp fearick $" ;
#endif
/****************************************************************************
PROGRAM: gnushell
a shell for gnuplot to allow plotting on pm with minimum hassle
MODULE: dialogs.c Dialog procedures for Gnushell
****************************************************************************/
/*
Copyright (c) 1992, Roger Fearick.
All rights reserved
THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT WARRANTIES OF ANY KIND.
Permission is hereby granted for personal, non-commercial use of this
software.You are granted the right to use, modify, and redistribute
it for for non-commercial purposes, provided that all copyright
notices remain intact and all changes are clearly documented.
THE AUTHOR MAKES NO WARRANTY OF ANY KIND WITH RESPECT TO THIS PRODUCT
AND EXPLICITLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY
OR FITNESS FOR ANY PARTICULAR PURPOSE.
*/
/* Update Log
**
* $Log: dialogs.c,v $
* Revision 1.2 1992/07/26 12:37:10 fearick
* Initial 32-bit version
*
* Revision 1.1 1992/07/25 15:44:12 fearick
* Initial revision
*
*
*/
#define INCL_PM
#define INCL_WIN
#define INCL_DEV
#define INCL_WINDIALOGS
#define INCL_WINBUTTONS
#define INCL_WINSYS
#define INCL_WINFRAMEMGR
#define INCL_WINPOINTERS
#define INCL_WINTRACKRECT
#define INCL_WINENTRYFIELDS
#define INCL_WINWINDOWMGR
#include <os2.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gnushell.h"
static FONTMETRICS *afm = NULL ; /* points to list of available fonts */
static long QFonts( HWND ) ;
MRESULT EXPENTRY PrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
/*
** print dialog box
*/
{
static idButton = 0 ;
static short shCaps = 0 ;
static char *szName ;
ULONG ulStyle ;
switch ( usMsg ) {
case WM_INITDLG :
szName = (char *) PVOIDFROMMP( mp2 ) ;
shCaps = QueryPrinterCaps( hwnd ) ;
if( shCaps & QP_CAPS_FILE ) {
ulStyle = WinQueryWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
QWL_STYLE ) ;
WinSetWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
QWL_STYLE, ulStyle ^ DT_HALFTONE ) ;
}
else {
WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
EM_SETREADONLY, TRUE, 0L ) ;
}
WinSendMsg ( WinWindowFromID ( hwnd , IDD_PRINTPIC ) ,
BM_CLICK , TRUE, NULL ) ;
break ;
case WM_COMMAND :
switch ( (SHORT) mp1 ) {
case DID_OK:
if( shCaps & QP_CAPS_FILE )
WinQueryDlgItemText( hwnd, IDD_QPRNAME, 32, szName ) ;
else
szName[0] = 0 ;
WinDismissDlg( hwnd, idButton ) ;
return 0L ;
case IDD_PRINTSETUP:
SetupPrinter( hwnd ) ;
return 0L ;
default:
break ;
}
case WM_CONTROL :
switch ( SHORT1FROMMP ( mp1 ) ) {
case IDD_PRINTPIC:
if( SHORT2FROMMP( mp1 ) == BN_CLICKED ) {
idButton = SHORT1FROMMP ( mp1 ) - IDD_PRINTPIC + IDM_PRINTPIC ;
return NULL ;
}
break ;
default: break ;
}
break ;
default:
break ;
}
/* fall through to the default control processing */
return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
}
static struct {
long lTech ; // printer technology
long lVer ; // driver version
long lWidth ; // page width in pels
long lHeight ; // page height in pels
long lWChars ; // page width in chars
long lHChars ; // page height in chars
long lHorRes ; // horizontal resolution pels / metre
long lVertRes ; // vertical resolution pels / metre
} prCaps ;
MRESULT EXPENTRY QPrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
/*
** Query print area and printer setup
*/
{
static PQPRINT pqp = NULL ;
TRACKINFO ti ;
RECTL rectlBox ;
static SWP swp ;
HDC hdc ;
switch ( usMsg ) {
case WM_INITDLG :
pqp = (PQPRINT) PVOIDFROMMP( mp2 ) ;
case WM_USER_SET_DATA :
WinSetDlgItemFloatF( hwnd, IDD_QPRXSIZE, 1, pqp->xsize ) ;
WinSetDlgItemFloatF( hwnd, IDD_QPRYSIZE, 1, pqp->ysize ) ;
WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
&rectlBox ) ;
WinQueryWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
&swp ) ;
rectlBox.xRight = rectlBox.yTop * pqp->xsize/pqp->ysize ;
WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
NULL, 0, 0, (short) rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE ) ;
rectlBox.xRight *= pqp->xfrac ;
rectlBox.yTop *= pqp->yfrac ;
WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
NULL,
swp.x, swp.y, //+(short)(swp.cy*(1.0-pqp->yfrac)),
(short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
if( pqp->caps & QP_CAPS_FILE ) {
;
}
else {
WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
EM_SETREADONLY, TRUE, 0L ) ;
}
break ;
case WM_COMMAND :
switch ( (SHORT) mp1 ) {
case DID_OK:
WinQueryDlgItemFloat( hwnd, IDD_QPRXFRAC, &pqp->xfrac ) ;
WinQueryDlgItemFloat( hwnd, IDD_QPRYFRAC, &pqp->yfrac ) ;
if( pqp->caps & QP_CAPS_FILE ) {
WinQueryDlgItemText( hwnd, IDD_QPRNAME, 16, pqp->name ) ;
}
break ;
case IDD_QPRSETPR: /* printer setup */
SetPrinterMode( hwnd ) ;
if( (hdc = OpenPrinterDC( WinQueryAnchorBlock( hwnd ), OD_INFO, NULL )) != DEV_ERROR ) {
DevQueryCaps( hdc, CAPS_TECHNOLOGY, (long)sizeof(prCaps)/sizeof(long), (PLONG)&prCaps ) ;
DevCloseDC( hdc ) ;
pqp->xsize = (float)100.0* (float) prCaps.lWidth / (float) prCaps.lHorRes ; // in cm
pqp->ysize = (float)100.0* (float) prCaps.lHeight / (float) prCaps.lVertRes ; // in cm
WinSendMsg( hwnd, WM_USER_SET_DATA, 0L, 0L ) ;
}
return 0L ;
case IDD_QPRTRACK : /* track plot area */
WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
&rectlBox ) ;
ti.cxBorder = ti.cyBorder = 2 ;
ti.cxGrid = ti.cyGrid = 0 ;
ti.cxKeyboard = ti.cyKeyboard = 2 ;
ti.ptlMinTrackSize.x = ti.ptlMinTrackSize.y = 2 ;
ti.rclBoundary = rectlBox ;
ti.ptlMaxTrackSize.x = rectlBox.xRight ;
ti.ptlMaxTrackSize.y = rectlBox.yTop ;
ti.rclTrack.xRight = pqp->xfrac * rectlBox.xRight ;
ti.rclTrack.yTop = pqp->yfrac*rectlBox.yTop ;
ti.rclTrack.xLeft = 0 ;
ti.rclTrack.yBottom = 0 ;//(1.0-pqp->yfrac) * rectlBox.yTop ;
ti.fs = TF_RIGHT|TF_TOP|TF_STANDARD|TF_SETPOINTERPOS|TF_ALLINBOUNDARY ;
WinSetPointer( HWND_DESKTOP,
WinQuerySysPointer( HWND_DESKTOP, SPTR_SIZENWSE, FALSE ) ) ;
WinTrackRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
NULL,
&ti ) ;
pqp->xfrac = (float)ti.rclTrack.xRight / (float)rectlBox.xRight ;
pqp->yfrac = ((float)(ti.rclTrack.yTop-ti.rclTrack.yBottom) / (float)rectlBox.yTop) ;
rectlBox.yTop = ti.rclTrack.yTop - ti.rclTrack.yBottom ;
rectlBox.xRight = ti.rclTrack.xRight ;
WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
NULL,
swp.x, swp.y,//+(short)(swp.cy*(1.0-pqp->yfrac)),
(short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
return 0L ;
default:
break ;
}
default:
break ;
}
/* fall through to the default control processing */
return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
}
MRESULT EXPENTRY QFontDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
/*
** query font dialog function
*/
{
extern HWND hApp ;
HWND hwndEx ;
HPS hps ;
short sCount, i ;
static HWND hwndLB ; // listbox handle
static long lCount = 0L ; // number of fonts found
static short shSize = 10 ; // point size of current selection
static char szFontName[50] ; // name of current font
static char szFontNameSize[50] ; // current font size&name combo
static char *pszFontNameSize ;
ULONG usItem ;
switch (msg) {
case WM_INITDLG:
pszFontNameSize = (PSZ) PVOIDFROMMP( mp2 ) ;
if( pszFontNameSize != NULL )
sscanf( pszFontNameSize, "%d", &shSize ) ;
WinSetDlgItemShort( hwnd, IDD_FONTSIZE, shSize, FALSE ) ;
hwndLB = WinWindowFromID( hwnd, IDD_HLIST ) ;
if( afm == NULL ) lCount = QFonts( hApp ) ;
sCount = (short) lCount ;
for( i=0; i<sCount;i++ ) {
if( afm[i].fsDefn & FM_DEFN_OUTLINE ) {
WinSendMsg( hwndLB,
LM_INSERTITEM,
LIT_END,
MPFROMP((PSZ)afm[i].szFacename) ) ;
}
}
WinSendMsg( hwndLB,
LM_SELECTITEM,
MPFROMSHORT( 0 ),
TRUE ) ;
break ;
case WM_USER_CHGFONT:
sprintf( szFontNameSize,
"%d.%s",
shSize,
szFontName ) ;
hwndEx = WinWindowFromID( hwnd, IDD_FONTEX ) ;
// hps = WinGetPS( hwndEx ) ;
WinSetPresParam(hwndEx,
PP_FONTNAMESIZE,
(ULONG)sizeof(szFontNameSize),
szFontNameSize ) ;
// WinReleasePS( hps ) ;
return 0L ;
case WM_CONTROL:
if( SHORT1FROMMP( mp1 ) == IDD_HLIST ) {
if( SHORT2FROMMP( mp1 ) == LN_SELECT ) {
usItem = (ULONG)WinSendMsg( hwndLB,
LM_QUERYSELECTION,
0L,
0L ) ;
WinSendMsg( hwndLB,
LM_QUERYITEMTEXT,
MPFROM2SHORT( usItem, 50 ),
MPFROMP((PSZ)szFontName) ) ;
WinQueryDlgItemShort( hwnd, IDD_FONTSIZE, &shSize, FALSE ) ;
if( shSize != 0 ) WinSendMsg( hwnd, WM_USER_CHGFONT, 0L, 0L ) ;
}
}
else if( SHORT1FROMMP( mp1 ) == IDD_FONTSIZE ) {
if( SHORT2FROMMP( mp1 ) == EN_CHANGE ) {
WinQueryDlgItemShort( hwnd, IDD_FONTSIZE, &shSize, FALSE ) ;
if( shSize != 0 ) WinSendMsg( hwnd, WM_USER_CHGFONT, 0L, 0L ) ;
}
}
break ;
case WM_COMMAND:
if (SHORT1FROMMP(mp1) == DID_OK) {
strcpy( pszFontNameSize, szFontNameSize ) ;
WinDismissDlg( hwnd, DID_OK );
return 0L;
}
break;
}
return WinDefDlgProc( hwnd, msg, mp1, mp2 ) ;
}
static long QFonts( HWND hwnd )
/*
** Get list of available fonts
*/
{
FONTMETRICS fm;
LONG lCount, lFontCount;
HPS hps;
hps = WinGetPS( hwnd ) ;
lCount = 0 ;
lFontCount = GpiQueryFonts(hps,
QF_PUBLIC,
NULL, /* queries all public fonts */
&lCount,
(LONG) (sizeof(fm)),
(PFONTMETRICS) &fm);
lCount = lFontCount ;
afm = malloc( lCount*sizeof(FONTMETRICS) ) ;
lFontCount = (long) GpiQueryFonts(hps,
QF_PUBLIC,
NULL, /* queries all public fonts */
&lCount,
(LONG) (sizeof(fm)),
(PFONTMETRICS) afm);
WinReleasePS( hwnd ) ;
return lCount ;
}